---------------------
-- dap
---------------------
local dap = require("dap")
dap.defaults.fallback.exception_breakpoints = { 'default' }
dap.defaults.python.exception_breakpoints = { 'uncaught' }
vim.fn.sign_define('DapBreakpoint', { text = '🛑', texthl = '', linehl = '', numhl = '' })
---------------------
-- dapui
---------------------
local dapui = require("dapui")
dapui.setup({
  -- Expand lines larger than the window
  expand_lines = true,
  mappings = {
    -- Use a table to apply multiple mappings
    expand = { "<Space>", "<2-LeftMouse>" },
    open = "<Cr>",
    remove = "x",
    edit = "e",
    repl = "r",
    toggle = "t",
  },
  layouts = {
    {
      elements = {
        { id = "scopes",      size = 0.4 },
        { id = "watches",     size = 0.2 },
        { id = "stacks",      size = 0.2 },
        { id = "breakpoints", size = 0.2 },
      },
      size = 0.25,
      position = "left",
    },
    {
      elements = {
        "repl";
      },
      size = 0.25,
      position = "bottom",
    },
  },
  controls = {
    enabled = vim.fn.has('nvim-0.8') > 0,
  },
  floating = {
    mappings = {
      close = { "<M-M>", "<Esc>", "<M-q>", "<C-c>" },
    },
  },
})
---------------------------------
-- auto open/close dapui
---------------------------------
dap.listeners.after.event_initialized["dapui_config"] = function()
  dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
  dapui.close({})
  dap.repl.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
  dapui.close({})
  -- dap.repl.close()
end
